import { createRouter, createWebHistory } from 'vue-router'
import Layout from '../layout/Layout.vue'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          name: 'Home',
          component: () => import('@/views/Home.vue')
        },
        {
          path: '/:pathMatch([a-z]{2,10})',
          name: 'Tools',
          component: () => import('@/views/Category.vue')
        },
        {
          path: '/user',
          name: 'User',
          component: () => import('../views/User.vue'),
          meta: {
            title: '个人中心'
          }
        },
        {
          path: '/login',
          name: 'Login',
          component: () => import('../views/Login.vue'),
          meta: {
            title: '登录'
          }
        },
        {
          path: '/register',
          name: 'Register',
          component: () => import('../views/Register.vue'),
          meta: {
            title: '注册'
          }
        },
        {
          path: '/:pathMatch(.*)*',
          name: 'NotFound',
          component: () => import('../views/NotFound.vue'),
          meta: {
            title: '页面未找到'
          },
          beforeEnter: (to, from, next) => {
            // 如果路径以 /admin 开头，则不匹配这个404路由
            if (to.path.startsWith('/admin')) {
              return false  // 返回 false 来阻止路由匹配
            }
            next()
          }
        }
      ]
    }
  ]
})



export default router 